package com.bit.aop.demo;

import com.bit.aop.demo.controller.TestController;
import com.bit.aop.demo.proxy.HouseSubject;
import com.bit.aop.demo.proxy.RealHouseSubject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringAopDemoApplication {

	public static void main(String[] args) {
		ApplicationContext context = SpringApplication.run(SpringAopDemoApplication.class, args);
		//默认情况下  cglib代理
		TestController bean = context.getBean(TestController.class);
		System.out.println(bean.getClass().toString());  //CGlib

		RealHouseSubject realHouseSubject = (RealHouseSubject) context.getBean("realHouseSubject");
		System.out.println(realHouseSubject.getClass().toString());  //SpringCGLIB

		HouseSubject houseSubject = (HouseSubject) context.getBean("realHouseSubject");
		System.out.println(houseSubject.getClass().toString()); //cglib


		//spring.aop.proxy-target-class=false   jdk动态代理
//		TestController bean = context.getBean(TestController.class);
//		System.out.println(bean.getClass().toString());  //CGlib

//		RealHouseSubject realHouseSubject = (RealHouseSubject) context.getBean("realHouseSubject");
//		System.out.println(realHouseSubject.getClass().toString());  //报错

//		HouseSubject realHouseSubject = (HouseSubject) context.getBean("realHouseSubject");
//		System.out.println(realHouseSubject.getClass().toString()); //JDK

	}

}
